package com.miracle.main.module.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.miracle.basemvp.base.BaseFragment;
import com.miracle.basemvp.di.component.AppComponent;
import com.miracle.main.R;
import com.miracle.main.R2;
import com.miracle.main.adapter.SecreteAdapter;
import com.miracle.main.module.di.component.DaggerSecretComponent;
import com.miracle.main.module.di.module.SecretModule;
import com.miracle.main.module.mvp.contract.SecretContract;
import com.miracle.main.module.mvp.entity.bean.SecretBean;
import com.miracle.main.module.mvp.entity.bean.TimeLineStatus;
import com.miracle.main.module.mvp.presenter.SecretPresenter;
import com.miracle.main.module.mvp.ui.activity.AddSecretActivity;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;

import java.util.ArrayList;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * com.miracle.main.module.mvp.ui.fragment
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/2 18:04
 * @see com.miracle.main.module.mvp.ui.fragment
 */
public class SecretFragment extends BaseFragment<SecretPresenter> implements SecretContract.View {

    @BindView(R2.id.rv)
    RecyclerView mRecyclerView;
    @BindView(R2.id.btn)
    FloatingActionButton mBtn;

    @Inject
    SecreteAdapter mAdapter;
    @Inject
    ArrayList<SecretBean> mList;


    @Override
    public int setLayoutId(@Nullable Bundle bundle) {
        return R.layout.cloud_fragment_secret;
    }

    @Override
    public void setDaggerComponent(AppComponent appComponent) {
        DaggerSecretComponent
                .builder()
                .appComponent(appComponent)
                .secretModule(new SecretModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void init(@Nullable Bundle bundle) {
        setDataListItems();
        initAdapter();

    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    private void initAdapter() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerView.setAdapter(mAdapter);
    }

    private void setDataListItems() {
        mList.add(new SecretBean("Item successfully delivered", "", TimeLineStatus.INACTIVE));
        mList.add(new SecretBean("Courier is out to delivery your order", "2017-02-12 08:00",
                TimeLineStatus.ACTIVE));
        mList.add(new SecretBean("Item has reached courier facility at New Delhi", "2017-02-11 " +
                "21:00", TimeLineStatus.COMPLETED));
        mList.add(new SecretBean("Item has been given to the courier", "2017-02-11 18:00",
                TimeLineStatus.COMPLETED));
        mList.add(new SecretBean("Item is packed and will dispatch soon", "2017-02-11 09:30",
                TimeLineStatus.COMPLETED));
        mList.add(new SecretBean("Order is being readied for dispatch", "2017-02-11 08:00",
                TimeLineStatus.COMPLETED));
        mList.add(new SecretBean("Order processing initiated", "2017-02-10 15:00", TimeLineStatus
                .COMPLETED));
        mList.add(new SecretBean("Order confirmed by seller", "2017-02-10 14:30", TimeLineStatus
                .COMPLETED));
        mList.add(new SecretBean("Order placed successfully", "2017-02-10 14:00", TimeLineStatus
                .COMPLETED));
    }

    @Override
    public void onRequest(LifecycleProvider<FragmentEvent> lifecycleProvider) {

    }

    @Override
    public void showData(Object o) {

    }

    @OnClick(R2.id.btn)
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.btn) {
            startActivity(new Intent(mContext,AddSecretActivity.class));
        }
    }
}
